package com.slipper.common.controller;

import com.slipper.listener.SessionListener;
import com.slipper.system.employee.bo.EmployeeBO;
import com.slipper.util.*;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/system/session")
public class SessionController {
    @Resource
    private SessionListener sessionListener;

    @PostMapping("/info")
    public String info() {
        Map<String, Object> data = new HashMap<>();
        data.put("onlineCount", sessionListener.getSessionCount());
        data.put("startTime", sessionListener.getStartTime().getTime());
        data.put("endTime", new Date().getTime());
        return ResultUtil.successResult(data);
    }

    @PostMapping("/onlineList")
    public String onlineList(@RequestBody EmployeeBO bo) {
        return ResultUtil.successResult(sessionListener.onlineList(bo));
    }

    @PostMapping("/forceOffline")
    public String forceOffline(@RequestBody EmployeeBO bo) {
        sessionListener.forceOffline(bo.getId());
        return ResultUtil.successResult("强制下线成功！");
    }
}
